package start;

public class T0059 {
    public static void main(String[] args) {
        int a=3;
        int [][]nums;

        nums=generateMatrix(3);


        System.out.println(nums[0][1]);


    }
    public static int[][] generateMatrix(int n) {
        int [][]nums=new int[n][n];

        int a=1;
        int b=0;
        int x=0;
        int y=0;
        int x1 ,x2,y1,y2;
        x1=y1=0;
        x2=y2=n-1;
        nums[0][0]=1;
        int nn=2;
//        System.out.println("初始"+x+"  "+y+"  "+x1+"  "+x2+"  "+y1+"  "+y2);
        while (nn<=n*n){
//            System.out.println(x+"  "+y+"  "+x1+"  "+x2+"  "+y1+"  "+y2);
            if(x+a<x1){
                System.out.println(11);
                a=0;
                b=-1;
                y2--;
                continue;
            }else if(x+a>x2){
//                System.out.println(22);
                a=0;
                b=1;
                y1++;
                continue;
            }else if(y+b<y1){
//                System.out.println(33);
                b=0;
                a=1;
                x1++;
                continue;
            }else if(y+b>y2){
//                System.out.println(44);
                b=0;
                a=-1;
                x2--;
                continue;
            }else {
                y=y+b;
                x=x+a;
                if(nums[y][x]==0){
                    nums[y][x]=nn++;

//                    System.out.println(nn);
                }
            }

        }



        return nums;



    }
}
